<%@ page contentType="text/html;charset=UTF-8" language="java" isELIgnored="false" %>
<html>
<head>
    <title>发送通知</title>
    <script type="text/javascript" src="../../static/common/ckeditor/ckeditor.js"></script>
    <script type="text/javascript" src="../../static/common/jquery/jquery-1.11.1.min.js"></script>
    <link rel="stylesheet" href="../../static/common/layui/css/layui.css">
    <script src="../../static/common/axios.min.js"></script>
</head>
<body>
<div style="margin: 15px;">
    <form class="layui-form" action="">
        <fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
            <legend>发送通知</legend>
        </fieldset>
        <div class="layui-form-item"style="width:913px;">
            <label class="layui-form-label">通知标题</label>
            <div class="layui-input-block">
                <input type="text" name="title"  autocomplete="off"  class="layui-input" value="" placeholder="请输入标题">
            </div>
        </div>
        <div style="    margin-left: 110px;">
            <textarea id="ta_ckeditor" class="ckeditor my-math" cols="20" rows="2" style="overflow:auto"></textarea>
            <script type="text/javascript">CKEDITOR.replace('ta_ckeditor');</script>
        </div>
        <div class="layui-form-item" style="width:913px;margin-top: 20px;">
            <label class="layui-form-label">来源</label>
            <div class="layui-input-block">
                <select name="source" lay-filter="source">
                    <option value=""></option>
                    <option value="学工">学工</option>
                    <option value="教务" >教务</option>
                    <option value="办公室">办公室</option>
                    <option value="团委">团委</option>
                </select>
            </div>
        </div>
        <div class="layui-form-item" style="width:913px;">
            <label class="layui-form-label">是否公开</label>
            <div class="layui-input-block">
                <select name="ispublic" lay-filter="ispublic">
                    <option value=""></option>
                    <option value="1">公开</option>
                    <option value="2">不公开</option>
                </select>
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-input-block">
                <button type="submit" class="layui-btn" lay-submit="" lay-filter="edit">发送通知</button>
                <button type="submit" class="layui-btn" onclick=" window.history.go(-1)">返回</button>
            </div>
        </div>
    </form>
</div>
<script src="../../static/common/layui/layui.js"></script>
<script>
    var myDate = new Date();
    layui.use(['form','jquery','layer'],function() {
        var form = layui.form(),
            $ = layui.jquery;
        var a,b;
        var da = new Date();
        var myDate=da.getFullYear() + "-" + (da.getMonth() + 1) + "-" + da.getDate() + " " + da.getHours() + ":" + da.getMinutes() + ":" + da.getSeconds();
        form.on('select(source)',function (data1) {
            a = data1.value;
            console.log(a);
        });
        form.on('select(ispublic)',function (data2) {
            b = data2.value;
        });
        form.on('submit(edit)', function (data) {
            axios.get('/magfacultyinfo/findOne/' +${sessionScope.currentUser.getId()})
                .then(function (response) {
                    console.log(response.data.data.school.id);
                    data.field.composerid = ${sessionScope.currentUser.getId()};
                    data.field.content= CKEDITOR.instances.ta_ckeditor.getData();
                    data.field.publishdate=myDate;
                    console.log(myDate);
                    data.field.source=a;
                    data.field.ispublic=b;
                    data.field.schoolid=response.data.data.school.id;
                    console.log(data.field);
                    $.ajax({
                        url:'/notice/add'
                        ,type:'post'
                        ,contentType : "application/json; charset=utf-8"
                        ,data:JSON.stringify(data.field)
                        ,dataType:'json'
                        ,success:function (response) {
                            layer.msg(response.message,function () {
//                                location.reload();
//                                parent.tab.deleteTab(parent.tab.getCurrentTabId());
                                location='/admin/message'
                            });
                        }
                    });
                })
                .catch(function (response) {
                    console.log(response);
                });
            return false;
        });
    })
</script>
</body>
</html>
